package com.sgzn.sgpay.web.controller;

import com.sgzn.sgpay.model.request.SgsBizOrderQueryPageRequest;
import com.sgzn.sgpay.model.request.util.PageQueryParam;
import com.sgzn.sgpay.model.response.SgsResultResponse;
import com.sgzn.sgpay.model.response.result.BizOrderQueryPageResult;
import com.sgzn.sgpay.service.SgsBizOrderService;
import com.sgzn.sgpay.web.controller.base.MerchantBaseController;
import com.sgzn.sgpay.web.handle.AssembleCommonHandle;
import com.sgzn.sgpay.web.request.Impl.BizOrderQueryPageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 业务订单管理控制器
 * @author huangsenguang
 * @version Id: BizOrderController.java, v 0.1 2018/5/1 11:08 huangsenguang Exp $$
 */
@Slf4j
@Controller
@RequestMapping("/merchant/bizOrder")
public class BizOrderController extends MerchantBaseController {
    @Autowired
    private SgsBizOrderService sgsBizOrderService;
    @Resource
    private AssembleCommonHandle assembleCommonHandle;

    /**
     * 分页查询订单的信息
     * @param request
     * @return
     */
    @RequestMapping("queryPage")
    @ResponseBody
    public SgsResultResponse<BizOrderQueryPageResult> queryPageBizOrder(BizOrderQueryPageRequest request) {
        super.setMchInfo(request);
        return this.sgsBizOrderService.queryPage(assembleQueryPageRequest(request));
    }

    /**
     * 组装服务请求
     * @param request
     * @return
     */
    private SgsBizOrderQueryPageRequest assembleQueryPageRequest(BizOrderQueryPageRequest request) {
        SgsBizOrderQueryPageRequest sgsBizOrderQueryPageRequest = new SgsBizOrderQueryPageRequest();
        this.assembleCommonHandle.assemble(request, sgsBizOrderQueryPageRequest);
        sgsBizOrderQueryPageRequest.setOrderId(request.getOrderId());
        sgsBizOrderQueryPageRequest.setBizState(request.getBizState());
        PageQueryParam pageQueryParam = new PageQueryParam();
        pageQueryParam.setPageSize(Integer.parseInt(request.getPageSize()));
        pageQueryParam.setCurrentPage(Integer.valueOf(request.getPageNum()));
        sgsBizOrderQueryPageRequest.setPageQueryParam(pageQueryParam);
        return sgsBizOrderQueryPageRequest;
    }
}

